&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v9r12
&ANALYZE-RESUME
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Include 
/*------------------------------------------------------------------------
    File        : 
    Purpose     :

    Syntax      :

    Description :

    Author(s)   :
    Created     :
    Notes       :
  ----------------------------------------------------------------------*/
/*          This .W file was created with the Progress AppBuilder.      */
/*----------------------------------------------------------------------*/

/* ***************************  Definitions  ************************** */

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK 

/* ********************  Preprocessor Definitions  ******************** */



/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME



/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
   Type: Include
   Allow: 
   Frames: 0
   Add Fields to: Neither
   Other Settings: INCLUDE-ONLY
 */
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
/* DESIGN Window definition (used by the UIB) 
  CREATE WINDOW Include ASSIGN
         HEIGHT             = 15
         WIDTH              = 60.
/* END WINDOW DEFINITION */
                                                                        */
&ANALYZE-RESUME

 


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Include 


/* ***************************  Main Block  *************************** */
IF docld.norub <> "" THEN DO:
   doce.totmtn  = doce.totmtn  + docld.montne + IF docld.taxi THEN 0
                                                ELSE docld.montx.
   doce.totqte  = doce.totqte + docld.montx.
   doce.totme   = doce.totmtn.
   doce.totmb   = doce.totme * doce.cours / doce.unit.
END.
ELSE DO:
    FIND arti WHERE arti.nosoc = docld.nosoc
                AND arti.ref   = docld.ref NO-LOCK NO-ERROR.

    ASSIGN docld.unit  = arti.unit
           docld.unitq = arti.unit
           docld.taux  = arti.taux
           docld.poids = docld.qteumb * arti.poids.

    FIND adrd WHERE adrd.nosoc = doce.nosoc
                AND adrd.noadr = doce.noadrf
                AND adrd.csmt  = doce.csmtf NO-LOCK NO-ERROR.

    RUN facrprix.p (docld.ref   ,docld.nosoc ,TRUE       ,doce.codmon,
                    "CHF"       ,arti.TYPE   ,adrd.typc  ,adrd.typc,
                    doce.noadrf ,doce.csmtf  ,doce.noadrl,doce.csmtl,
                    docld.qteumb,docld.qteumb,doce.datdoc,arti.unit,
                    arti.unit,OUTPUT docld.rabais
                             ,OUTPUT buf-pumb
                             ,OUTPUT docld.punite
                             ,OUTPUT docld.unitp
                             ,OUTPUT docld.nocpt
                             ,OUTPUT docld.taxi).

    ASSIGN docld.montbe = buf-pumb * docld.qteumb
           docld.montne = (docld.montbe * docld.rabais) / 100
           docld.montne = docld.montbe - docld.montne.

    FIND FIRST taxe WHERE taxe.code  = doce.taux   AND
                          taxe.lang  = 2           AND
                          taxe.datv <= doce.datdoc NO-LOCK NO-ERROR.
    IF AVAILABLE taxe THEN DO:
       IF taxe.taux = 0 THEN ASSIGN docld.taux  = doce.taux
                                    docld.montx = 0
                                    docld.taxi  = FALSE.
       ELSE DO:
          FIND FIRST taxe WHERE taxe.code  = docld.taux  AND
                                taxe.lang  = 2           AND
                                taxe.datv <= doce.datdoc
                                NO-LOCK NO-ERROR.
          ASSIGN docld.montx = docld.montne - docld.mtrabg
                 docld.montx = docld.montx * IF docld.taxi THEN taxe.tauxi
                                             ELSE               taxe.taux
                 docld.montx = docld.montx / 100.
       END.
       IF docld.taxi THEN
          ASSIGN docld.montmb = ((docld.montne - docld.montx - docld.mtrabg) * doce.cours)
                 docld.montmb = docld.montmb / doce.unit.
       ELSE docld.montmb = ((docld.montne - docld.mtrabg) * doce.cours) / doce.unit.
       docld.montmb = ROUND(docld.montmb,2).
    END.
    ELSE DO:
       docld.montmb = ((docld.montne - docld.mtrabg) * doce.cours) / doce.unit.
       docld.montmb = ROUND(docld.montmb,2).
    END.

    doce.totmtn  = doce.totmtn  + docld.montne + IF docld.taxi THEN 0
                                                 ELSE docld.montx.
    doce.totqte  = doce.totqte + docld.montx.
    doce.totme   = doce.totmtn.
    doce.totmb   = doce.totme * doce.cours / doce.unit.

    FIND dliv WHERE dliv.nosoc   = docld.nosoc
                AND dliv.typdoc  = docld.typdoc
                AND dliv.prefix  = docld.prefix
                AND dliv.nodoc   = docld.nodoc
                AND dliv.noseq   = docld.noseq
                AND dliv.nosui   = 5
                NO-ERROR.
    IF NOT AVAILABLE dliv THEN DO:
       CREATE dliv.
       ASSIGN dliv.nosoc   = docld.nosoc
              dliv.typdoc  = docld.typdoc
              dliv.prefix  = docld.prefix
              dliv.nodoc   = docld.nodoc
              dliv.noseq   = docld.noseq
              dliv.nosui   = 5.
    END.

    ASSIGN dliv.qteumb  = docld.qtec
           dliv.qteumq  = docld.qtec
           dliv.solde   = docld.qtec
           dliv.nostoc  = docld.nostoc
           dliv.deldd   = ?
           dliv.delait  = dliv.deldd
           dliv.noadrf  = doce.noadrf
           dliv.csmtf   = doce.csmtf
           dliv.noadrl  = doce.noadrl
           dliv.csmtl   = doce.csmtl
           dliv.nodos   = doce.nodos
           dliv.ref     = docld.ref.

    RUN tdrrdt2s.p (dliv.deldd, OUTPUT dliv.delds).
END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


